package org.wu.framework.inner.lazy.orm.solon.config;


import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.translation.adapter.LazyTranslationAdapter;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.translation.advanced.LazyTranslationAdvanced;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.translation.advanced.LazyTranslationAdvancedTarget;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.translation.api.DefaultLazyTableTranslation;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.translation.api.LazyTableTranslationOneAPI;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.translation.api.LazyTableTranslationOneToManyAPI;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.translation.api.LazyTranslationAPI;

import java.util.List;

/**
 * 转译配置类
 */
@Slf4j
@Configuration
public class LazyTranslationSolonAutoConfigure {


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 数据库转译

    /**
     * 默认转译对象
     *
     * @return LazyTranslationAPI
     */
    @Bean
//    @ConditionalOnMissingBean({LazyTranslationAPI.class})
    public LazyTranslationAPI lazyTableTranslationAPI() {
        return new LazyTableTranslationOneAPI();
    }


    @Bean
//    @ConditionalOnMissingBean({LazyTranslationAPI.class})
    public LazyTranslationAPI lazyTableTranslationOneToManyAPI() {
        return new LazyTableTranslationOneToManyAPI();
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * 默认转译对象
     *
     * @return
     */
    @Bean
//    @ConditionalOnMissingBean({LazyTranslationAPI.class})
    public LazyTranslationAPI lazyTranslationAPI() {
        return new DefaultLazyTableTranslation();
    }

    /**
     * 转换适配者 目标
     *
     * @param lazyTranslationAPIList 转换的api
     * @return
     */
    @Bean
    public LazyTranslationAdvancedTarget lazyTranslationAdvancedTarget(List<LazyTranslationAPI> lazyTranslationAPIList) {
        return new LazyTranslationAdvancedTarget(lazyTranslationAPIList);
    }


    /**
     * 转换适配器
     *
     * @param lazyTranslationAdvancedList
     * @return
     */
    @Bean
    @Condition(onMissingBean = LazyTranslationAdapter.class)
    public LazyTranslationAdapter lazyTranslationAdapter(List<LazyTranslationAdvanced> lazyTranslationAdvancedList) {
        return new LazyTranslationAdapter(lazyTranslationAdvancedList);
    }


//    /**
//     * 转译适配器切面注入
//     *
//     * @param translationAdapter 转换适配器
//     * @return
//     */
//    @Bean
//    @Condition(onMissingBean = LazyTranslationPointcutAdvisor.class)
//    public LazyTranslationPointcutAdvisor lazyTranslationPointcutAdvisor(LazyTranslationAdapter translationAdapter) {
//        return new LazyTranslationPointcutAdvisor(translationAdapter);
//    }

}
